package com.fbinggun.fbinggunutil.plugin;

import dev.lone.itemsadder.api.CustomBlock;

import dev.lone.itemsadder.api.CustomStack;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;

/**
 * ItemsAdder插件API
 */
public class ItemsAdderUtil {

    /**
     * 通过方块ID 获得方块
     * @param blockName 方块ID
     * @return
     */
    public static Block getBlock(String blockName){
        CustomBlock block = CustomBlock.getInstance(blockName);
        if(block==null){
            return null;
        }
        return block.getBlock();
    }
    public static String getBlockType(Block block){
        CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
        if(customBlock==null){
            return null;
        }
        return customBlock.getId();
    }



    /**
     *
     * @param blockName
     * @return
     */
    public static ItemStack getBlockItem(String blockName){
        CustomBlock block =CustomBlock.getInstance(blockName);
        if(block==null){
            if(Material.getMaterial(blockName)!=null&&Material.getMaterial(blockName).isBlock()){
                return  new ItemStack(Material.getMaterial(blockName));
            }
            return null;
        }
        return block.getItemStack();
    }


    public static ItemStack getItem(String name){
        CustomStack item =CustomStack.getInstance(name);
        if(item==null){
//            if(Material.getMaterial(name)!=null){
//                return  new ItemStack(Material.getMaterial(name));
//            }
            return null;
        }
        return item.getItemStack();
    }

    public static String getType(ItemStack itemStack){
        CustomStack item =CustomStack.byItemStack(itemStack);
        if(item==null){
            return itemStack.getType().name();
        }else {
            return item.getId();
        }

    }




}
